package server.handler.friendHandler;

import com.alibaba.fastjson.JSONObject;
import common.EnvelopeMessage;
import common.bodies.FriendShipBody;
import server.dao.FriendDao;
import server.handler.SimpleHandler;
import server.session.Session;

public class FriendBlockHandler implements SimpleHandler {
    @Override
    public void handle(EnvelopeMessage msg, Session session) {
        JSONObject body = msg.getBody();
        FriendShipBody ship = body.getObject("friendship",FriendShipBody.class);
        String user1Name = body.getString("fromName");
        Integer user1Id = body.getInteger("fromId");
        Integer user2Id = ship.getUser1Id().equals(user1Id)?ship.getUser2Id():ship.getUser1Id();
        String user2Name = ship.getUser1Name().equals(user1Name)?ship.getUser2Name(): ship.getUser1Name();
        FriendShipBody blockShip = new FriendShipBody(user1Id,user1Name,user2Id,user2Name,2);
        new FriendDao().updateFriendShip(blockShip);
    }
}
